package com.zb.order.controller;


import com.zb.entity.SelectVo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjWorkSlaModuleService;
import com.zb.service.ZjWorkSlaService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkSlaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单SLA表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-02-04
 */
@Api(tags = "工单SLA类接口")
@RestController
@RequestMapping("/work/sla")
public class ZjWorkSlaController {
    @Resource
    private ZjWorkSlaService workSlaService;
    @Resource
    private ZjWorkSlaModuleService workSlaModuleService;
    @ApiOperation("获取已选择的适用模块")
    @GetMapping("/getWorkSlaModule")
    public Result getWorkSlaModule(HttpServletRequest request) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取已选择的适用模块成功").data(PageUtil.rows(workSlaModuleService.getModuleIdByCustaccId(custAccId, null)));
    }

    @ApiOperation("新增或修改SLA")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid WorkSlaVo slaVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workSlaService.save(custAccId, slaVo);
        return Result.success(null == slaVo.getId()? "新增SLA成功" : "修改SLA成功");
    }

    @ApiOperation("获取工单策略SLA列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取工单策略SLA列表成功").data(workSlaService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据工单策略SLA ID获取修改前的数据")
    @GetMapping("/getBeforeEditData/{id}")
    public Result getBeforeEditData(@PathVariable @ApiParam(value = "工单策略SLA ID", required = true) Long id) {
        return Result.success("获取修改前的数据成功").data(PageUtil.row(workSlaService.getBeforeEditData(id)));
    }

    @ApiOperation("根据工单策略SLA ID获取详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "工单策略SLA ID", required = true) Long id) {
        return Result.success("获取详情成功").data(PageUtil.row(workSlaService.getDetail(id)));
    }

    @ApiOperation("批量启用或禁用工单策略SLA")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "工单策略SLA状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "工单策略SLA ID", required = true) List<Long> ids) {
        workSlaService.updateDisabledBatchById(ids, status);
        return Result.success(status? "禁用SLA成功" : "启用SLA成功");
    }

    @ApiOperation("批量删除工单策略SLA")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "工单策略SLA ID", required = true) List<Long> ids) {
        workSlaService.deleteBatchByIds(ids);
        return Result.success("删除工单策略SLA成功");
    }

}
